package org.jash.mvp2206.video;

import android.content.Intent;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import org.jash.mvp2206.R;
import org.jash.mvp2206.entity.AllVideo;
import org.jash.mvp2206.mvp.BaseFragment;

import java.util.List;

public class VideoFragment extends BaseFragment<Construct.IVideoView, VideoPresenter> implements Construct.IVideoView {
    private RecyclerView recycler;
    private VideoAdapter adapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_video;
    }

    @Override
    protected void initData() {
        presenter = new VideoPresenter();
        presenter.getAllVideo();
    }

    @Override
    protected void initView() {
        recycler = findViewById(R.id.recycler);
        adapter = new VideoAdapter();
        adapter.setListener(bean -> startActivity(new Intent(requireContext(), PlayerActivity.class).putExtra("url", bean.getVideourl())));
        recycler.setAdapter(adapter);
    }

    @Override
    public void success(List<AllVideo.DataBean> bean) {
        adapter.addAll(bean);
    }

    @Override
    public void failure(Throwable t) {
        Toast.makeText(requireContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
    }
}